package paint;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import kevin.kCachedFileLoader;

public class PaintIcon extends PaintComponent {
	protected Image icon;
	private Color outlineColor;

	public PaintIcon(int x, int y, String location, Color outlineColor) {
		if (location != null) {
			try {
				icon = Toolkit.getDefaultToolkit().getImage(new File(location).toURL());
			} catch (MalformedURLException e) {
				e.printStackTrace();
			}
		}

		bounds = new Rectangle(x, y, icon.getWidth(null), icon.getHeight(null));
		this.outlineColor = outlineColor;
	}

	public PaintIcon(int x, int y, URL location, Color outlineColor) {
		if (location != null) {
			icon = Toolkit.getDefaultToolkit().getImage(new kCachedFileLoader(location).getURL());
		}

		bounds = new Rectangle(x, y, icon.getWidth(null), icon.getHeight(null));
		this.outlineColor = outlineColor;
	}

	protected void changeIcon(String location) {
		try {
			changeIcon(new File(location).toURL());
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	}

	protected void changeIcon(URL location) {
		icon = Toolkit.getDefaultToolkit().getImage(location);
	}

	@Override
	public void paint(Graphics g) {
		g.drawImage(icon, bounds.x, bounds.y, null);

		if (outlineColor != null) {
			g.setColor(outlineColor);
			g.drawRect(bounds.x, bounds.y, getWidth(), getHeight());
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}
}
